/**
 * 商家消息 API 封装
 */

import request from '@/utils/request'

/**
 * 分页获取商家消息
 * @param {Object} params - 查询参数
 * @param {Number} params.type - 消息类型（可选）
 * @param {Number} params.current - 当前页
 * @param {Number} params.size - 每页大小
 * @returns {Promise}
 */
export function getMerchantMessages(params) {
  const query = { ...(params || {}) }
  if (
    query.type === null ||
    query.type === undefined ||
    query.type === '' ||
    String(query.type).toLowerCase() === 'null'
  ) {
    delete query.type
  }
  return request({
    url: '/merchant/message/page',
    method: 'GET',
    params: query
  })
}

/**
 * 获取未读消息数
 * @returns {Promise}
 */
export function getMerchantUnreadCount() {
  return request({
    url: '/merchant/message/unread-count',
    method: 'GET'
  })
}

/**
 * 标记单条消息已读
 * @param {Number} id - 消息ID
 * @returns {Promise}
 */
export function markMerchantMessageRead(id) {
  return request({
    url: `/merchant/message/${id}/read`,
    method: 'POST'
  })
}

/**
 * 全部标记已读
 * @returns {Promise}
 */
export function markAllMerchantMessagesRead() {
  return request({
    url: '/merchant/message/read-all',
    method: 'POST'
  })
}
